<?php

class ImagenesController extends Zend_Controller_Action
{
	
	
	   protected  $scriptImagenes =  "(function(window, $, PhotoSwipe){			
			$(document).ready(function(){				
				$('div.gallery-page')
					.live('pageshow', function(e){						
						var currentPage = $(e.target),
							options = {},
							photoSwipeInstance = $(\"ul.gallery a\", e.target).photoSwipe(options,  currentPage.attr('id'));							
						return true;						
					})					
					.live('pagehide', function(e){						
						var currentPage = $(e.target),
							photoSwipeInstance = PhotoSwipe.getInstance(currentPage.attr('id'));
						if (typeof photoSwipeInstance != \"undefined\" && photoSwipeInstance != null) {
							PhotoSwipe.detatch(photoSwipeInstance);
						}						
						return true;						
					});				
			});}(window, window.jQuery, window.Code.PhotoSwipe));";
	 
	
	
	protected $_usuarioLogueado = null;
	
	public function init ()
    {
    	
    	if(!Zend_Auth::getInstance()->hasIdentity())  
        {  
            $this->_redirect('/Index/');  
        }
         $this->_usuarioLogueado = Zend_Auth::getInstance()->getIdentity(); 
         
        /* Initialize action controller here */
    	$this->view->title = "IMAGENES";
     
     		
		//$this->view->headScript()->appendScript($scriptImagenes,'text/javascript');

    }

    public function indexAction()
    {
        //carga las imagenes de una articulo especifico
    	$idArticulo = $this->_getParam('idArticulo');   
    	$tablaArticulos = new Application_Model_DbTable_Articulo();
        try {
        	$imagenes = $tablaArticulos->imagenesPorArticulo($idArticulo);
        	if (is_array($imagenes) && count($imagenes) > 0) {
        		$this->view->headScript()->appendScript($this->scriptImagenes,'text/javascript');
        		$this->view->imagenes = $imagenes;
        	}else{
        		$this->view->imagenes = array();
        	}        	
        	
        } catch (Exception $e) {
        	throw new Exception("Fallaaa ".$e);
        }        
    }


}

